package mo.leetcode_top;

public class L50 {

    public double myPow(double x, int n) {
        //需要考虑n==0的情况
        if (n == 0) {
            return 1;
        }
        if (n == 1) {
            return x;
        }
        if (n == -1) {
            return 1.0 / x;
        }
        if (n % 2 == 0) {
            return myPow(x * x, n / 2);
        } else {
            if (n < 0) {
                return myPow(x * x, n / 2) * (1.0 / x);
            } else {
                return myPow(x * x, n / 2) * x;
            }
        }

    }

    public static void main(String[] args) {
        L50 test = new L50();
        System.out.println(test.myPow(2, 4));
        System.out.println(Math.pow(-0.42, 0));
    }

}
